package com.juguo.charginganimation;

import android.app.Application;
import android.content.SharedPreferences;

import com.fenghuajueli.lib_ad.AdConfig;
import com.fenghuajueli.lib_ad.AdShowUtils;
import com.hjq.permissions.BuildConfig;
import com.hjq.permissions.XXPermissions;
import com.juguo.charginganimation.Data.ApiAddress;
import com.squareup.leakcanary.LeakCanary;

public class MainApplication extends Application {
    private static MainApplication sInstance;
    public boolean isShowAd;
    //是否是第一次使用
    private boolean isFirstUse;
    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
        // 当前项目是否已经适配了分区存储的特性
        XXPermissions.setScopedStorage(true);
        //穿山甲SDK初始化
        SharedPreferences preferences = getSharedPreferences("isFirstUse", MODE_PRIVATE);
        isFirstUse = preferences.getBoolean("isFirstUse", false);
        if (isFirstUse) {
            ThirdPartySdk();
        }

        //內存檢測
        if (LeakCanary.isInAnalyzerProcess(this)) {
            // This process is dedicated to LeakCanary for heap analysis.
            // You should not init your app in this process.
            return;
        }
        LeakCanary.install(this);
    }

    public void ThirdPartySdk() {
        //强烈建议在应用对应的Application#onCreate()方法中调用，避免出现content为null的异常
        AdConfig config = new AdShowUtils.AdConfigBuilder()
                .setAdAppId(ApiAddress.CSJ_APP_ID)
                .setSplashId(ApiAddress.CSJ_CODE_ID)
                .setInteractionExpressId(ApiAddress.CSJ_CHAP_ID)
                .builder();
        AdShowUtils.getInstance().initAdConfig(this, BuildConfig.DEBUG, config);
    }


    public static MainApplication getsInstance() {
        return sInstance;
    }
}
